package com.example.hissys.mapper;

import com.example.hissys.dto.NotificationDetailDTO;
import com.example.hissys.dto.NotificationRequest;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface NotificationMapper {
    /**
     * 获取用户的所有通知
     */
    @Select("SELECT n.*, " +
            "a.appointment_date, a.appointment_time, a.payment_status " +
            "FROM notifications n " +
            "LEFT JOIN appointments a ON n.appointment_id = a.id " +
            "WHERE n.user_id = #{userId} " +
            "ORDER BY n.created_at DESC")
    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "title", column = "title"),
        @Result(property = "content", column = "content"),
        @Result(property = "status", column = "status"),
        @Result(property = "createdAt", column = "created_at"),
        @Result(property = "appointmentId", column = "appointment_id"),
        @Result(property = "appointmentDate", column = "appointment_date"),
        @Result(property = "appointmentTime", column = "appointment_time"),
        @Result(property = "paymentStatus", column = "payment_status")
    })
    List<NotificationDetailDTO> findByUserId(@Param("userId") Integer userId);

    /**
     * 将通知标记为已读
     */
    @Update("UPDATE notifications SET status = 'read' WHERE id = #{id} AND user_id = #{userId}")
    int markAsRead(@Param("id") Integer id, @Param("userId") Integer userId);

    @Insert("INSERT INTO notifications (user_id, title, content, status) " +
            "VALUES (#{userId}, #{title}, #{content}, 'unread')")
    int create(NotificationRequest request);
} 